<?php

use think\facade\Route;

/** 后台管理接口 */
Route::group('admin/video', function () {
    // 课程管理
    Route::group(function () {
        Route::get('list', 'index')->name('course.video.list');    // 点播列表数据
        Route::get('create', 'create')->name('course.video.create'); // 创建课程-页面
        Route::post('create', 'create')->name('course.video.create'); // 创建课程-提交
        Route::get('marquee', 'marquee')->name('course.video.marquee'); // 跑马灯配置
        Route::post('marquee', 'marquee')->name('course.video.marquee'); // 跑马灯配置
        // 单课程 <id> 课程ID
        Route::group('<id>', function () {
            Route::get('edit$', 'update');      // 修改课程-页面
            Route::put('$', 'update');      // 修改课程-提交
            Route::put('edit/<field>$', 'editField');   // 编辑指定字段 <field> 字段名称（ps：如状态）

            Route::delete('$', 'delete')->name('course.video.delete'); // 删除课程-软删除
            Route::post('finished', 'sectionFinish')->name('course.video.section.finish'); // 完结课时
        })->pattern([
            'id'    => '\d+',
            'field' => '[a-zA-Z_]+',
        ]);
        Route::put('listing', 'listing');// 批量上架
        Route::put('disables', 'disables');// 批量禁用
        Route::delete('deletes/<ids>', 'deletes')->pattern(['ids' => '[\d,]+']);// 批量删除
    })->prefix('\app\course\service\video\admin\Video@');
    // 课时管理
    Route::group('<id>/section', function () {
        Route::get('$', 'sectionTree')->name('course.video.section.tree'); // 课时树
        Route::get('<pid>/create$', 'addSection');  // 创建课时
        Route::post('<pid>$', 'addSection');  // 创建课时
        Route::get('<sid>/edit$', 'update');      // 编辑课时
        Route::put('<sid>$', 'update');      // 编辑课时
        Route::put('<sid>/sort$', 'updateSort');   // 编辑课时best_sort字段
        Route::delete('<sid>$', 'delete')->name('course.video.section.delete'); // 删除课时
        Route::get('<pid>$', 'getChildren'); // 课时子集
    })
        ->prefix('\app\course\service\video\admin\VideoSection@')
        ->pattern([
            'id'  => '\d+', // 课程ID
            'pid' => '\d+', // 课时父级ID
            'sid' => '\d+', // 课时ID
        ]);
    // 课时审核
    Route::group('examine', function () {
        Route::get('list', 'index');
        Route::get('<id>/handle', 'handle');
        Route::post('<id>/handle', 'handle');
    })
        ->prefix('\app\course\service\video\admin\ExamineVideoSection@')
        ->pattern(['id' => '\d+']);
    /** 点播课学员接口 */
    Route::group('<course_id>/student', function () {
        // 获取学员列表
        Route::get('list', '@getStudentList')->append(['course_type' => 1]);
        Route::post('export', '@exportStudent')->append(['course_type' => 1]);
        // ->middleware(['apiTest', 'withoutLogin'])
        // ->option(['is_api' => 0]);
        Route::delete('<student_id>/delete', '@removeStudent')->append(['course_type' => 1]);
        Route::get('<student_id>/info', '@learnInfo')->append(['course_type' => 1]);
    })
        ->prefix('\app\course\service\base\admin\CourseStudent')
        ->pattern([
            'course_id'  => '\d+',
            'student_id' => '\d+',
        ]);
    /** 点播订单 */
    Route::group('order', function () {
        // 订单列表
        Route::get('list', 'index');
        // 订单导出
        Route::post('export', 'export');
    })->prefix('\app\course\service\video\admin\Order@');

})->middleware(['adminRoute']);
